/**
    入驻小区
**/
(function (vc) {
    let DEFAULT_PAGE = 1;
    let DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            partnerGoodsInfo: {
                partnerGoodss: [],
                partners:[],
                total: 0,
                records: 1,
                moreCondition: false,
                pgId: '',
                conditions: {
                    ppId: '',
                    valueId: '',
                    prodName: '',
                    prodDesc: '',
                    state: '',

                }
            }
        },
        _initMethod: function () {
            $that._listPartners();
           
        },
        _initEvent: function () {
            vc.on('partnerGoods', 'listPartnerGoods', function (_param) {
                $that._listPartnerGoodss(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listPartnerGoodss(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listPartnerGoodss: function (_page, _rows) {
                $that.partnerGoodsInfo.conditions.page = _page;
                $that.partnerGoodsInfo.conditions.row = _rows;
                $that.partnerGoodsInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                let param = {
                    params: $that.partnerGoodsInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/partnerGoods.listPartnerGoods',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.partnerGoodsInfo.total = _json.total;
                        $that.partnerGoodsInfo.records = _json.records;
                        $that.partnerGoodsInfo.partnerGoodss = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.partnerGoodsInfo.records,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _toSendGoodsToPartner: function () {
                let _ppId = $that.partnerGoodsInfo.conditions.ppId;
                if(!_ppId){
                    vc.toast('请选择合作商')
                    return ;
                }
                vc.jumpToPage('/#/pages/partner/transferPartnerGoods?ppId='+_ppId);
            },

            _toSendGoodsPriceToPartner: function (_partnerGoods) {
                let _ppId = $that.partnerGoodsInfo.conditions.ppId;
                if(!_ppId){
                    vc.toast('请选择合作商')
                    return ;
                }
                vc.emit('syncPartnerGoodsPrice','openSyncPartnerGoodsPriceModal', {
                    ppId:_ppId
                });
            },
            _toSendGoodsStockToPartner: function (_partnerGoods) {
                let _ppId = $that.partnerGoodsInfo.conditions.ppId;
                if(!_ppId){
                    vc.toast('请选择合作商')
                    return ;
                }
                vc.emit('syncPartnerGoodsStock','openSyncPartnerGoodsStockModal',  {
                    ppId:_ppId
                });
            },
            _openDeletePartnerGoodsModel: function (_partnerGoods) {
                vc.emit('deletePartnerGoods', 'openDeletePartnerGoodsModal', _partnerGoods);
            },
            _queryPartnerGoodsMethod: function () {
                $that._listPartnerGoodss(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.partnerGoodsInfo.moreCondition) {
                    $that.partnerGoodsInfo.moreCondition = false;
                } else {
                    $that.partnerGoodsInfo.moreCondition = true;
                }
            },
            _listPartners: function (_page, _rows) {

                let param = {
                    params: {
                        page:1,
                        row:100,
                        shopId:vc.getCurrentCommunity().shopId
                    }
                };

                //发送get请求
                vc.http.apiGet('/partner.listPartnerPool',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.partnerGoodsInfo.partners = _json.data;
                        if(_json.data && _json.data.length >0){
                            $that.partnerGoodsInfo.conditions.ppId = _json.data[0].ppId;
                            $that._listPartnerGoodss(DEFAULT_PAGE, DEFAULT_ROWS);
                        }
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
        }
    });
})(window.vc);
